package aes.gui;

import java.awt.CardLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTextPane;

import aes.general.Exam;

/**
 * The Class TeacherCommentPanel. This panel is allowing the teacher the option to add comments to exam
 * while composing it. The teacher is also able to indicate if the comments 
 * will be visible to the student or not.
 */
public class TeacherCommentPanel extends JPanel {

	/**
	 *  
	 */
	private static final long serialVersionUID = 1L;
	private JPanel jp;
	private JLabel l1;
	private JLabel lblSetVisebleTo;
	private JButton button;
	private JButton btnSave;
	private JCheckBox chckbxNewCheckBox;
	private JTextPane text;
	private JSeparator separator;
	
	/**
	 * The exam.
	 */
	private Exam exam;
	
	/**
	 * Create the panel.
	 * 
	 * @param contentPane
	 *            the content pane
	 * @param exam
	 *            the exam
	 */
	public TeacherCommentPanel(JPanel contentPane,Exam exam) {
		this.jp = contentPane;
		this.exam = exam;
		setLayout(null);
		initialize();
	}

	/**
	 * Initialize.
	 */
	private void initialize()
	{
		l1 = new JLabel("Add Comments");
		l1.setFont(new Font("Tempus Sans ITC", Font.BOLD, 21));
		l1.setBounds(224, 11, 191, 29);
		add(l1);
		
		separator = new JSeparator();
		separator.setBounds(10, 43, 620, 2);
		add(separator);
		
		button = new JButton("<<Back");
		button.setBounds(208, 403, 91, 23);
		add(button);
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				text.setText(null);
				chckbxNewCheckBox.setSelected(false);
				CardLayout cl = (CardLayout)(jp.getLayout());
					cl.show(jp,"ExamPanel");
			}
		});
		
		btnSave = new JButton("Save");
		btnSave.setBounds(324, 403, 91, 23);
		add(btnSave);
		btnSave.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				exam.setDescription(text.getText());
				text.setText(null);
				chckbxNewCheckBox.setSelected(false);
				CardLayout cl = (CardLayout)(jp.getLayout());
					cl.show(jp,"ExamPanel");
			}
		});
		
		text = new JTextPane();
		text.setBounds(62, 84, 503, 217);
		add(text);
		
		lblSetVisebleTo = new JLabel("Set Visibility:");
		lblSetVisebleTo.setFont(new Font("Sylfaen", Font.BOLD, 12));
		lblSetVisebleTo.setBounds(62, 333, 91, 14);
		add(lblSetVisebleTo);
		
		chckbxNewCheckBox = new JCheckBox("Allow For Students To See",false);
		chckbxNewCheckBox.setBounds(159, 329, 191, 23);
		add(chckbxNewCheckBox);
		chckbxNewCheckBox.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
						if(chckbxNewCheckBox.isSelected())
							exam.setVisible(true);
						else
							exam.setVisible(false);		
			}
		});
	}
}
